// -*-mode:c++; coding:utf-8-*-

#ifndef _XBASE_KV_SCANNER_MANAGER_HPP_
#define _XBASE_KV_SCANNER_MANAGER_HPP_

#include <ext/hash_map>
#include <map>

#include <boost/thread/mutex.hpp>

#include "tablet.hpp"

namespace xbase {
	// tablet_scanner_manager
	class kv_scanner_manager {
	public:
		kv_scanner_manager ();

		~kv_scanner_manager ();

		void add_scanner (const tablet_scanner::pointer &p_scanner);
		tablet_scanner::pointer get_scanner (const uint64_t &p_id) const;
		void close_scanner (const uint64_t &p_id);

		// @p p_interval in seconds
		void close_expired_scanners (const uint32_t &p_interval);

		void close_scanner_on_tablet(const std::string &tablet_name);
	private:
		mutable boost::mutex m_mutex;
		typedef __gnu_cxx::hash_map<uint64_t, tablet_scanner::pointer> scanner_map_type;
		scanner_map_type m_scanner_map;
		
		typedef std::multimap<std::string, uint64_t> tablet_scanner_map;
		tablet_scanner_map m_tablet_scanner_map;
	};
} // namespace xbase


#endif	// _XBASE_KV_SCANNER_MANAGER_HPP_
